package library;

import java.util.Date;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;


@DatabaseTable(tableName = "booking_record")
public class BookingRecord {
	@DatabaseField(generatedId = true)
	private int id;
	@DatabaseField(canBeNull = false)
	private Date borrowDate;
	@DatabaseField(canBeNull = false)
	private int user_id;
	@DatabaseField(foreign = true, columnName = "res_id", foreignAutoRefresh = true)
	private Book book;
	
	private User user;
	
	public BookingRecord(){

	}
	
	public Date getBorrowDate() {
		return borrowDate;
	}

	public void setBorrowDate(Date borrowDate) {
		this.borrowDate = borrowDate;
	}

	
	public BookingRecord(Book borrowBook, Date date, User bookingUser) throws Exception{
		book = borrowBook;
		borrowDate = date;
		user = bookingUser;	
		user_id = user.getId();
	}

    public String getBookName(){
        return book.getName();
    }

	public String toString(){
		return String.format("Book name: %s,(id %s) \t Booked Date: %s \t Record Id: %s ", 
			book.getName(),book.getId() ,borrowDate.toString(),id);
	}
	
}
